parts = input().split(",")
num = int(parts[0])
base = int(parts[1])
result = int(str(num), base)
print(result)